package main;

import javax.swing.SwingUtilities;
import view.ViewFrame;

/**
 *
 * @author Roderick
 */
public class Launcher {
    private static SplashWindow splashWindow;
    private static Launcher instance = null;

    public static Launcher getInstance(){
        if(instance == null)
            instance = new Launcher();
        return instance;
    }
   
    public static void main(String[] args) throws Exception {
        getInstance().load();
    }

    private void showSplashScreen() throws Exception{
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run(){
                splashWindow = new SplashWindow();
                splashWindow.setVisible(true);
            }
        });        
    }
    private void loadPropierties() throws Exception{
        SwingUtilities.invokeAndWait(new Runnable() {
                public void run()
                {
                    splashWindow.setPercentageComplete(0.04166667F * 5 );
                }
            }
        );
        synchronized(this)
        {
            wait(500L);
        }
    }
    private void loadModules() throws Exception{
        SwingUtilities.invokeAndWait(new Runnable() {
                public void run()
                {
                    splashWindow.setPercentageComplete(0.04166667F * 10 );
                }
            }
        );
        synchronized(this)
        {
            wait(500L);
        }
    }
    private void showMainWindow() throws Exception{
        //----------------------------------------------------------------------

        //----------------------------------------------------------------------
        SwingUtilities.invokeAndWait(new Runnable() {
                public void run()
                {
                    splashWindow.setPercentageComplete(0.04166667F * 15 );
                }
            }
        );
        synchronized(this)
        {
            wait(500L);
        }
        //----------------------------------------------------------------------

        //----------------------------------------------------------------------
        SwingUtilities.invokeAndWait(new Runnable() {
                public void run()
                {
                    splashWindow.setPercentageComplete(0.04166667F * 24 );
                    ViewFrame frame = new ViewFrame();
                    frame.setVisible(true);
                    

                }
            }
        );
        //----------------------------------------------------------------------
    }

    public void load( ) throws Exception {
        showSplashScreen();
        loadPropierties();
        loadModules();
        showMainWindow();
        synchronized(this)
        {
            wait(11500L);
        }
        splashWindow.dispose();
    }

    
}
